import 'package:flutter/material.dart';
import 'package:mobile_app.core/core/presentation/theme/styles.dart';
import 'package:mobile_app.home.core/core/presentation/theme/home_core_styles.dart';

part 'styles.dart';

part 'text_theme.dart';

class GoogleAppleStorePurchasePageTheme extends InheritedTheme {
  GoogleAppleStorePurchasePageTheme({
    required Brightness brightness,
    required Color primaryContrastingColor,
    required super.child,
    super.key,
  })  : _brightness = brightness,
        _primaryContrastingColor = primaryContrastingColor,
        _data = _buildThemeData(
          brightness: brightness,
          primaryContrastingColor: primaryContrastingColor,
        );

  final Brightness _brightness;
  final Color _primaryContrastingColor;
  final GoogleAppleStorePurchasePageThemeData _data;

  static GoogleAppleStorePurchasePageThemeData _buildThemeData({
    required Brightness brightness,
    required Color primaryContrastingColor,
  }) {
    return switch (brightness) {
      Brightness.dark => GoogleAppleStorePurchasePageThemeData.dark(
        primaryContrastingColor: primaryContrastingColor,
      ),
      Brightness.light => GoogleAppleStorePurchasePageThemeData.light(
        primaryContrastingColor: primaryContrastingColor,
      ),
    };
  }

  static GoogleAppleStorePurchasePageThemeData of(BuildContext context) {
    final inheritedTheme =
        context.dependOnInheritedWidgetOfExactType<GoogleAppleStorePurchasePageTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme =
        context.findAncestorWidgetOfExactType<GoogleAppleStorePurchasePageTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return GoogleAppleStorePurchasePageTheme(
      brightness: _brightness,
      primaryContrastingColor: _primaryContrastingColor,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(GoogleAppleStorePurchasePageTheme oldWidget) {
    return _brightness != oldWidget._brightness ||
        _primaryContrastingColor != oldWidget._primaryContrastingColor;
  }
}

class GoogleAppleStorePurchasePageThemeData {
  const GoogleAppleStorePurchasePageThemeData._internal({
    required this.imageBackgroundColor,
    required this.backgroundColor,
    required this.imageFloorColor,
    required this.purchaseItemTileColor,
    required this.pageClosingIconColor,
    required this.purchaseItemTileShadows,
    required this.textTheme,
  });

  factory GoogleAppleStorePurchasePageThemeData.light({
    required Color primaryContrastingColor,
  }) {
    return GoogleAppleStorePurchasePageThemeData._internal(
      imageBackgroundColor: GoogleAppleStorePurchasePageStyles.imageBackgroundColorLight,
      backgroundColor: Colors.white,
      imageFloorColor: GoogleAppleStorePurchasePageStyles.imageFloorColorLight,
      purchaseItemTileColor: GoogleAppleStorePurchasePageStyles.purchaseItemTileColorLight,
      pageClosingIconColor: CoreStyles.grey4,
      purchaseItemTileShadows: [
        const BoxShadow(
          color: CoreStyles.lightGrey5,
          blurRadius: 5.0,
          spreadRadius: 1.0,
        ),
      ],
      textTheme: GoogleAppleStorePurchasePageTextTheme.light(
        primaryContrastingColor: primaryContrastingColor,
      ),
    );
  }

  factory GoogleAppleStorePurchasePageThemeData.dark({
    required Color primaryContrastingColor,
  }) {
    return GoogleAppleStorePurchasePageThemeData._internal(
      imageBackgroundColor: GoogleAppleStorePurchasePageStyles.imageBackgroundColorDark,
      backgroundColor: CoreStyles.darkGrey4,
      imageFloorColor: GoogleAppleStorePurchasePageStyles.imageFloorColorDark,
      purchaseItemTileColor: GoogleAppleStorePurchasePageStyles.purchaseItemTileColorDark,
      pageClosingIconColor: CoreStyles.grey2,
      purchaseItemTileShadows: const [],
      textTheme: GoogleAppleStorePurchasePageTextTheme.dark(
        primaryContrastingColor: primaryContrastingColor,
      ),
    );
  }

  final Color imageBackgroundColor;
  final Color backgroundColor;
  final Color imageFloorColor;
  final Color purchaseItemTileColor;
  final Color pageClosingIconColor;
  final List<BoxShadow> purchaseItemTileShadows;
  final GoogleAppleStorePurchasePageTextTheme textTheme;
}
